package com.sams.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.sams.entity.Leader;
import com.sams.service.LeaderService;

@RequestMapping("/leader")
@Controller
public class LeaderController {
	
	@Autowired
	private LeaderService service;
	
	//分页查询
	@RequestMapping("/list")
	public String listLeader(Integer currentPage,Model model) {
		if(currentPage==null || currentPage ==0) {
			currentPage=1;
		}
		PageInfo<Leader> pageInfo= service.listLeader(currentPage);
		model.addAttribute("pageInfo",pageInfo);
		return "leader";
	}
	
	
	//删除领导信息
	@RequestMapping("/delete/{id}")
	public String delete(@PathVariable("id") Integer id) {
		service.delete(id);
		return "forward:/leader/list";
	}
	
	//添加领导信息
	@RequestMapping("/add")
	public String add(Leader leader) {
		service.add(leader);
		return "forward:/leader/list";
	}
	
	//修改领导信息
	@RequestMapping("/update")
	public String update(Leader leader) {
		service.update(leader);
		return "forward:/leader/list";
	}
	

}
